import arcpy

##JOHNTALBOT
##THIS SCRIPT DETERMINES THE CLOSEST POINT FOR EACH STORM
def main():
    fc= "C:\\storms.gdb\\spatial_point_join"
    cursor=arcpy.UpdateCursor(fc)
    stormlist=[]
    for i in cursor:
        x=1
        for j in stormlist:
            if i.Serial_Num==j:
                x=0
                break
        if x==1:
            stormlist.append(i.Serial_Num)
    del cursor
    del i
    numlist=[]
    for stormID in stormlist:
        minimum=99999999
        cursor=arcpy.UpdateCursor(fc)
        for row in cursor:
            if str(row.Serial_Num) == str(stormID): # &//(row.YMD[0]!='A'))
                if float(row.Kilometers) < float(minimum):
                    minimum=float(row.Kilometers)
                    obj=row.OBJECTID
        cursor.reset()
        print stormID, "dist", minimum, obj
        numlist.append(obj)
    print numlist
    del cursor
    
    arcpy.AddField_management(fc,"X","SHORT")
    po=0
    cursor=arcpy.UpdateCursor(fc)
    for p in cursor:
        
        for d in numlist:
            if str(p.OBJECTID) == str(d):
                p.X = 1
                po=po+1
                
        cursor.updateRow(p)
    
    print po
            
        
main()    
    
